package com.sykj.cloud.activity.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sykj.cloud.common.log.enums.LogUserType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.activity.domain.ActivityOrder;
import com.sykj.cloud.activity.service.IActivityOrderService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 活动订单记录Controller
 *
 * @author mr.will
 * @date 2021-04-01
 */
@RestController
@RequestMapping("/order")
public class ActivityOrderController extends BaseController
{
    @Autowired
    private IActivityOrderService activityOrderService;

    /**
     * 新增活动订单记录
     */
    @PreAuthorize(hasPermi = "activity:order:add")
    @Log(title = "活动订单记录", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityOrder activityOrder)
    {
        return toAjax(activityOrderService.insertActivityOrder(activityOrder));
    }

    /**
     * 修改活动订单记录
     */
    @PreAuthorize(hasPermi = "activity:order:edit")
    @Log(title = "活动订单记录", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityOrder activityOrder)
    {
        return toAjax(activityOrderService.updateActivityOrder(activityOrder));
    }

    /**
     * 删除活动订单记录
     */
    @PreAuthorize(hasPermi = "activity:order:remove")
    @Log(title = "活动订单记录", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(activityOrderService.deleteActivityOrderByIds(guids));
    }

    /**
     * 获取活动订单记录详细信息
     */
    @PreAuthorize(hasPermi = "activity:order:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(activityOrderService.getActivityOrderById(guid));
    }

    /**
     * 导出活动订单记录列表
     */
    @PreAuthorize(hasPermi = "activity:order:export")
    @Log(title = "活动订单记录", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityOrder activityOrder) throws IOException
    {
        List<ActivityOrder> list = activityOrderService.listActivityOrders(activityOrder);
        ExcelUtil<ActivityOrder> util = new ExcelUtil<ActivityOrder>(ActivityOrder.class);
        util.exportExcel(response, list, "order");
    }

    /**
    * 查询活动订单记录列表
    */
    @PreAuthorize(hasPermi = "activity:order:list")
    @GetMapping("/list")
        public TableDataInfo list(ActivityOrder activityOrder)
    {
        startPage();
        List<ActivityOrder> list = activityOrderService.listActivityOrders(activityOrder);
        return getDataTable(list);
    }
    }
